Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add users support #6

Draft
wants to merge 27 commits into
base: next
Choose a base branch
from
Draft

feat: add users support #6

wants to merge 27 commits into from

Conversation

ooliver1
Copy link
Member

Description

This PR adds users support, added in https://github.com/eludris/eludris/tree/enoki/users. This has not been merged into next yet, so neither will this PR.

Details in order of diff:

Configuration is stored in ~/.config/pilfer/Pilfer.toml (user token), like the Eludris CLI in eludris/eludris#79. This is too, configurable via PILFER_CONF.

Documentation in the README has been added for existing and new keybinds.

Authentication is done once HELLO has been received. heartbeat_interval is actually in milliseconds, not seconds, which was an issue since pilfer would disconnect and reconnect.

A list has been added to the right of the messages box, which is togglable using Ctrl + U. This is a list of currently online users (not OFFLINE) - so ONLINE, IDLE, and BUSY. It is stored as a hashmap of id: User for now. This is so it can be updated easily and quickly when receiving a PRESENCE_UPDATE. It is not necessary to store this in a simplified structure containing display name and status, since the User struct is already small. If a user is not known, it is fetched from the API and added to the hashmap.

Instances of msg.message.content have been altered to use msg.message.content as in todel, this is a flattened common struct. A Box is used around Pilfer::Eludris() as eludris message structs are not as small as they used to be, and this is passed around a lot.

The instance version is checked against the pilfer package version. Right now, it must be 0.4.0-alpha1 or greater to not fail. If the instance is lower, an error is printed, suggesting usage of INSTANCE_URL for the next instance or some other instance. If the instance is higher, an error is thrown, suggesting updating pilfer.

run_app is used under spawn_blocking as it should be ran in an executor for terminal.draw(|f| ui(f, &app)) to use locks in a blocking manner. This means that terminal is then passed back to the caller, to avoid Arc+Mutex usage. run_app contains a closure with the inner logic, as the terminal also needs to be returned. This avoids having to return (terminal, err) on error, and terminal on success. A bool is used for if the loop should continue, or not (Ctrl + C).

MessageResponse has been changed to Response<T> to be more universal, as it can then be more universally used for API errors.

The user list is rendered inside the same chunk as messages, so it can then be optionally split horizontally. The users list is locked at 20 characters to be big enough to read, but small enough to not be intrusive. Ctrl + U can still get rid of it in stupidly small terminal windows.

Users are authenticated using an initial Y/n prompt for logging in or registering. Username/email is then prompted in both cases, and password via rpassword for cross-platform hidden input. In the signup case, if InstanceInfo.email_address exists, the user is reminded to use pilfer --verify with their email verification code. platform is the OS's human lowercase name, such as linux, windows, macos, ..., and client is pilfer.

This is a Code Change

  • Changes have been tested.

@ooliver1 ooliver1 added the enhancement New feature or request label Jun 17, 2023
@ooliver1 ooliver1 requested a review from EnokiUN June 17, 2023 17:38
@ooliver1 ooliver1 changed the base branch from main to next June 17, 2023 17:39
Copy link
Member

@EnokiUN EnokiUN left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a

Cargo.toml Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/version.rs Outdated Show resolved Hide resolved
@ooliver1 ooliver1 requested a review from EnokiUN June 17, 2023 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants